package com.koron.car.web.maintain.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.car.web.maintain.bean.entity.AcceptRecord;
import com.koron.car.web.maintain.service.AcceptRecordService;
import com.koron.common.core.config.ThreadLocalContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/acceptRecord")
@Api(tags = "车辆管理-维修保养验收")
public class AcceptRecordController {
    /**
     * 服务对象
     */
    @Autowired
    private AcceptRecordService acceptRecordService;

    @GetMapping("/selectOne")
    @ApiOperation("根据车辆验收id查询信息")
    @ApiImplicitParam(name = "acceptId", value = "车辆验收id", required = true)
    public Response<AcceptRecord> selectOne(String acceptId) {
        log.info("根据车辆验收id查询信息， acceptId = {}", acceptId);
        AcceptRecord bean = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), acceptRecordService, "queryById", AcceptRecord.class, acceptId);
        return Response.ok(bean);
    }

    @GetMapping("/queryList")
    @ApiOperation("根据条件查询车辆验收列表")
    public Response<PageInfo<AcceptRecord>> queryList(AcceptRecord query) {
        log.info("根据条件查询车辆验收列表， query = {}", JSON.toJSONString(query));
        List<AcceptRecord> beans = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), acceptRecordService, "queryList", List.class, query);
        return Response.ok(new PageInfo<>(beans));
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("创建/修改车辆验收")
    public Response<AcceptRecord> saveOrUpdate(@RequestBody AcceptRecord acceptRecord) {
        log.info("创建/修改车辆验收， acceptRecord = {}", JSON.toJSONString(acceptRecord));
        AcceptRecord bean = ADOConnection.runTask(ThreadLocalContext.get().getCurrDs(), acceptRecordService, "saveOrUpdate", AcceptRecord.class, acceptRecord);
        return Response.ok(bean);
    }
}
